#!/bin/bash

echo "=== 验证最大化窗口调整功能 ==="

# 检查应用是否运行
if ! pgrep -f "WindowsStyleTaskbar" > /dev/null; then
    echo "❌ WindowsStyleTaskbar 未运行，启动应用..."
    open build/WindowsStyleTaskbar.app
    sleep 3
fi

echo "✅ WindowsStyleTaskbar 正在运行"

echo ""
echo "=== 当前窗口信息 ==="
# 获取所有窗口信息
osascript << 'EOF'
tell application "System Events"
    set allProcesses to every process whose background only is false
    repeat with proc in allProcesses
        try
            set procName to name of proc
            set allWindows to every window of proc
            repeat with win in allWindows
                try
                    set winName to name of win
                    set winPosition to position of win
                    set winSize to size of win
                    log "窗口: " & procName & " - " & winName & " 位置: " & (item 1 of winPosition) & "," & (item 2 of winPosition) & " 大小: " & (item 1 of winSize) & "x" & (item 2 of winSize)
                on error
                    -- 跳过无法访问的窗口
                end try
            end repeat
        on error
            -- 跳过无法访问的进程
        end try
    end repeat
end tell
EOF

echo ""
echo "=== 屏幕信息 ==="
# 获取屏幕信息
osascript << 'EOF'
tell application "Finder"
    set screenBounds to bounds of window of desktop
    log "主屏幕边界: " & (item 1 of screenBounds) & "," & (item 2 of screenBounds) & " to " & (item 3 of screenBounds) & "," & (item 4 of screenBounds)
end tell
EOF

echo ""
echo "=== 测试说明 ==="
echo "1. 请手动将一个窗口（如VSCode）最大化"
echo "2. 观察窗口是否自动调整高度避开任务栏"
echo "3. 检查任务栏是否显示在所有屏幕的底部"
echo "4. 验证任务栏项目是否正确显示应用图标和窗口标题"

echo ""
echo "按 Ctrl+C 退出监控..."

# 持续监控窗口变化
while true; do
    sleep 5
    echo "$(date): 监控中..."
done